package com.iman.Confucius.service.impl.student;

import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.iman.Confucius.service.student.ClazzService;
import com.iman.Confucius.vo.teacher.TeacherClassPair;
import com.iman.common.hibernate.HibernateSupport;
import com.iman.common.hibernate.TemplateQLService;

@Service("clazzService")
public class ClazzServiceImpl implements ClazzService {

	@Inject
    TemplateQLService templateQLService;

    @Inject
    HibernateSupport  hibernateSupport;
	
	@SuppressWarnings("unchecked")
	@Override
	public List<TeacherClassPair> getTeacherClassPairByStudent(Long userId) {
		StringBuilder sql = new StringBuilder("select tt.teacher_id, tt.classes_id ");
		sql.append(" from drm_classes_teacher_real tt, drm_classes_members_real tm");
		sql.append(" where tt.classes_id=tm.classes_id");
		sql.append(" and tt.use_yn=1");
		sql.append(" and tm.member_id=:userId");
		sql.append(" and tm.use_yn=1");
		Map<String, Long> paramMap = new HashMap<String, Long>();
		paramMap.put("userId", userId);
		List<Object> result= hibernateSupport.findBySQLQuery(sql.toString(), paramMap);
		List<TeacherClassPair> resultList = new ArrayList<TeacherClassPair>();
		for(Object obj: result){
			Object[] tempObj = (Object[]) obj;
			TeacherClassPair tcPair = new TeacherClassPair(((BigInteger)tempObj[0]).longValue(), ((BigInteger)tempObj[1]).longValue());
			resultList.add(tcPair);
		}
		return resultList;
	}

}
